Simple Iteration Constructs

The constructs <#2539#>dolist<#2539#> and <#2540#>dotimes<#2540#> execute a body of code once for each value taken by a single variable. They are expressible in terms of <#2541#>do<#2541#>, but capture very common patterns of use.

Both <#2542#>dolist<#2542#> and <#2543#>dotimes<#2543#> perform a body of statements repeatedly. On each iteration a specified variable is bound to an element of interest that the body may examine. <#2544#>dolist<#2544#> examines successive elements of a list, and <#2545#>dotimes<#2545#> examines integers from 0 to #tex2html_wrap_inline6452# - 1 for some specified positive integer <#2547#>n<#2547#>.

The value of any of these constructs may be specified by an optional result form, which if omitted defaults to the value <#2548#><#2548#>.

The <#2549#>return<#2549#> statement may be used to return immediately from a <#2550#>dolist<#2550#> or <#2551#>dotimes<#2551#> form, discarding any following iterations that might have been performed; in effect, a <#2552#>block<#2552#> named <#2553#><#2553#> surrounds the construct. The body of the loop is implicitly a <#2554#>tagbody<#2554#> construct; it may contain tags to serve as the targets of <#2555#>go<#2555#> statements. Declarations may appear before the body of the loop.


#defmac2556#


#defmac2582#

See also <#2626#>do-symbols<#2626#>, <#2627#>do-external-symbols<#2627#>, and <#2628#>do-all-symbols<#2628#>.